package com.qidian.study.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
 * @author 戴着假发的程序员
 * @company 起点编程
 */
public class DateFormat {
    public static Date string2date(String d,String p){
        if(d==null){
            return new Date();
        }
        if(p==null || "".equals(p)){
            p = "yyyy-MM-dd HH:mm:ss";
        }
        try {
            return new SimpleDateFormat(p).parse(d);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }
    public static String date2String(Date d,String p){
        if(d==null){
            d = new Date();
        }
        if(p==null || "".equals(p)){
            p = "yyyy-MM-dd HH:mm:ss";
        }
        return new SimpleDateFormat(p).format(d);
    }

    public static String getNowString(){
        String   p = "yyyy-MM-dd HH:mm:ss";
        return new SimpleDateFormat(p).format(new Date());
    }
}
